﻿using Red.Controls.ViewModels;
using Red.Core;
using Red.EngineData.View;
using System.Windows.Controls;

namespace Red.Toolkit.AnimationGraphEditor.Pages
{
    /// <summary>
    /// Interaction logic for VariablesAndEventsPage.xaml
    /// </summary>
    public partial class VariablesAndEventsPage : UserControl
    {
        public VariablesAndEventsPage()
        {
            InitializeComponent();
        }

        internal void Init( DataView dataView )
        {
            DataContext = new VariablesAndEventsPageViewModel( dataView );
        }
    }

    internal class VariablesAndEventsPageViewModel : ViewModel
    {
        private InteropDataItem _boolVariables;
        public InteropDataItem BoolVariables
        {
            get
            {
                return _boolVariables;
            }
            set
            {
                _boolVariables = value;
                OnPropertyChanged();
            }
        }

        private InteropDataItem _intVariables;
        public InteropDataItem IntVariables
        {
            get
            {
                return _intVariables;
            }
            set
            {
                _intVariables = value;
                OnPropertyChanged();
            }
        }

        private InteropDataItem _floatVariables;
        public InteropDataItem FloatVariables
        {
            get
            {
                return _floatVariables;
            }
            set
            {
                _floatVariables = value;
                OnPropertyChanged();
            }
        }

        private InteropDataItem _vectorVariables;
        public InteropDataItem VectorVariables
        {
            get
            {
                return _vectorVariables;
            }
            set
            {
                _vectorVariables = value;
                OnPropertyChanged();
            }
        }

        public VariablesAndEventsPageViewModel( DataView dataView )
        {
            var boolVariablesView = dataView.GetSubView( "boolVariables" );
            var intVariablesView = dataView.GetSubView( "intVariables" );
            var floatVariablesView = dataView.GetSubView( "floatVariables" );
            var vectorVariablesView = dataView.GetSubView( "vectorVariables" );

            InteropDataItem.CreateRoot( boolVariablesView, item => { BoolVariables = item; } );
            InteropDataItem.CreateRoot( intVariablesView, item => { IntVariables = item; } );
            InteropDataItem.CreateRoot( floatVariablesView, item => { FloatVariables = item; } );
            InteropDataItem.CreateRoot( vectorVariablesView, item => { VectorVariables = item; } );
        }
    }
}
